﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ScrumTime.Models.AcceptanceCriteria>" %>


<script>


    function getLiOfOl_ac(nameOfOl) {
        var testlist = [];

        $('#ol-acceptanceCriteria-uaffectedAC li').each(function () {
            testlist.push($(this).attr('affectedAcceptanceCriteriaId'));
        });

        return testlist.join("-");
    }


    function showStory_save_AcceptanceCriteria() {
        var storyId = $('#showStory_AcceptanceCriteria_StoryId').val();
        var acceptanceCriteriaId = $('#showStory_AcceptanceCriteria_AcceptanceCriteriaId').val();

        var description = $('#showStoryAcceptanceCriteria-description').val();

        var v_usabilityAffected_ac = getLiOfOl_ac();
        var url = addURLRamdon('/AcceptanceCriteria/Save');
        $.post(url,
                {
                    storyId: storyId,
                    acceptanceCriteriaId: acceptanceCriteriaId,
                    description: description,
                    usabilityaffectedAc: v_usabilityAffected_ac
                },
                function (data) {
                    if (verificarError(data)) return;
                    LoadAcceptanceCriterias();
                }
        );
    }

    function ShowStoryAcceptanceCriteriaSave() {
        showStory_save_AcceptanceCriteria();
        return true;
    }

    function ShowStoryAcceptanceCriteriaCancel() {
        LoadAcceptanceCriterias();
        return true;
    }

    function LoadAcceptanceCriterias() {
        var storyid = $("#show-story-basicdata-idStory").val();
        var url = addURLRamdon('/Story/ShowStory_AcceptanceCriterias');
        $.post(url,
                {
                    id: storyid
                },
                function (data) {
                    if (verificarError(data)) return;
                    $("#div_main_show_story_AcceptanceCriteriaList").html(data);
                }
            );

    }

</script>
<input type="hidden" id="showStory_AcceptanceCriteria_AcceptanceCriteriaId" />
<input type="hidden" id="showStory_AcceptanceCriteria_StoryId" />
<table style="width:100%;">
    <tr>
        <td>
            <table>
                <tr>
                    <td>
                        id:
                    </td>
                    <td>
                        <input type="text" id="showStoryAcceptanceCriteria-id"  disabled="disabled" />
                    </td>
                </tr>                
                <tr>
                    <td>
                        description:
                    </td>
                    <td>
                        <textarea id="showStoryAcceptanceCriteria-description" rows="3" cols="50"><%: Model.Description %></textarea>
                    </td>
                </tr>
                
            </table>
        </td>
    </tr>
    <tr>
        <td>
             <div id="div-info-acceptanceCriteria-uaffectedAC" style="border-width:1px;">
                <span>Usability Affected Acceptance Criteria</span>
                    <ol id="ol-acceptanceCriteria-uaffectedAC">
			            <%
                            foreach (ScrumTime.Models.UsabilityAffectedAcceptanceCriteria uac in Model.UsabilityAffectedAcceptanceCriterias)                             
                            {
                                
                            %>
                              <li id="li_atac_<%:uac.UsabilityAffectedAcceptanceCriteriaId%>"  affectedAcceptanceCriteriaId="<%:uac.UsabilityAffectedAcceptanceCriteriaId%>" > <%:uac.Description%> <a href="#" onclick="remove_li_af_AcceptanceCriteria(<%:uac.UsabilityAffectedAcceptanceCriteriaId%>)">&lt;remove&gt;</a> </li>  
                            <%
                            }
                        %>
		            </ol>
            </div>    
        </td>
    </tr>
    <tr>
        <td>
            <button id="show-story-AcceptanceCriteria-button-edit" onclick="ShowStoryAcceptanceCriteriaSave();">Save</button>
            <button id="show-story-AcceptanceCriteria-button-cancel"  onclick="ShowStoryAcceptanceCriteriaCancel();">Cancel</button>
        </td>    
    </tr>

</table>

<script>
    $("#show-story-AcceptanceCriteria-button-edit").button();
    $("#show-story-AcceptanceCriteria-button-cancel").button();

    $("#showStory_AcceptanceCriteria_AcceptanceCriteriaId").val('<%:Model.AcceptanceCriteriaId %>');
    $("#showStory_AcceptanceCriteria_StoryId").val('<%:Model.StoryId %>');
    $("#showStoryAcceptanceCriteria-id").val('<%:Model.AcceptanceCriteriaId %>');
    
</script>